package com.example.administrator.xueya;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.view.WindowManager;

import java.util.List;

/**
 * Created by Mr_su on 2017/5/14.
 */

public class CharView extends View {

    private float[] linezuobiao;
    private Paint linepaint;
    private int space;
    private int height;
    private Paint pointP;
    private float[] pointzuobiao;

    public CharView(Context context) {
        super(context);
        init(context,null);
    }

    public CharView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context,attrs);
    }

    public CharView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context,attrs);
    }

    private void init(Context context,AttributeSet attrs) {
        TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.CharView);
        String model = array.getString(R.styleable.CharView_showmmodel);
        //获取屏幕宽度，获取当前的模式为周还是月模式，评分屏幕为几等份
        WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        int width =  manager.getDefaultDisplay().getWidth();
        height = manager.getDefaultDisplay().getHeight();
        linepaint = new Paint();
        linepaint.setColor(getResources().getColor(R.color.gray));
        linepaint.setStrokeWidth(2);
        linepaint.setStyle(Paint.Style.FILL);
        pointP = new Paint();
        pointP.setColor(getResources().getColor(R.color.colorPrimary));
        pointP.setStyle(Paint.Style.FILL);
        pointP.setStrokeWidth(3);
        if (model.equals("week")){
            //画竖线使用
            space = width / 7;
            //坐标数组
            linezuobiao = new float[28];
            for (int i = 0; i < 7 ;i++){
                linezuobiao[4*i] = space *(i+1);//下面点x坐标
                linezuobiao[4*i+1] = 0;//下面点y坐标
                linezuobiao[4*i+2] = space *(i+1);//上面点x坐标
                linezuobiao[4*i+3] = height;//上面点y坐标
            }
        }else if (model.equals("month")){

        }
    }
    public void drawPoint(List<Integer> xueya){
        //血压范围是0-250
        //得到七个数据，
        pointzuobiao = new float[xueya.size()*2];
        for (int i = 0; i<xueya.size();i++){
            //第一个点space*1,xueya.get(1)*height/300
            //第二个点space*2，xueya.get(2)*height/300
            //第三个点space*3，xueya.get(3)*height/300
            pointzuobiao[i*2] = space*(i+1);
            pointzuobiao[i*2+1] = xueya.get(i)*height/300;
        }
        invalidate();
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //画竖线
        canvas.drawLines(linezuobiao,linepaint);
        //画点，区分空心和实心点
        canvas.drawPoints(pointzuobiao,pointP);

        //画折线


    }
}
